<?php
class Email extends CI_Model {

    var $name   = '';
    var $email = '';
    var $status ='';

	function get_all_email(){
    	$query = $this->db->query("SELECT email,name FROM email WHERE status = 1");
		return $query->result_array();
    }
	function get_email($start,$limit,$sort='id',$dir='ASC')
    {
	   	$query = $this->db->query("SELECT * FROM email ORDER BY $sort $dir LIMIT $start,$limit");
		return $query->result_array();
        
    }
	function get_total()
    {
	    $query = $this->db->query('SELECT count(*) as total FROM email');
		$row = $query->row_array();
        return $row['total'];
    }
    function insert_email($data)
    {
        $this->filterData($data);
        $this->db->insert('email', $data);
        return $this->db->insert_id()  ;
    }
	function get_by_id($id)
    {
	    $this->db->where('id',$id);
		$query = $this->db->get("email");
        return $query->row_array();
        
    }
    function update_email($data,$id)
    {
		$this->filterData($data);
        return $this->db->update('email', $data, array('id' => $id));
    }
    function delete_email($id){
    	$this->db->delete('email', array('id' => $id)); 
    }
	protected function filterData(&$data){
		foreach($data as $key=>$row){
			if (!$this->db->field_exists($key, 'email'))
			{
				unset($data[$key]);
			} 
		}
    }
    
}